from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import sys

class QlineEditValidator(QWidget):
    def __init__(self):
        super(QlineEditValidator, self).__init__()
        self.initUI()
    def initUI(self):

        self.setWindowTitle("校验器")
        formLayout = QFormLayout()
        intLineEdit = QLineEdit()
        doubleLineEdit = QLineEdit()
        validatorLineEdit = QLineEdit()

        formLayout.addRow("整数类型", intLineEdit)
        formLayout.addRow("双精度类型", doubleLineEdit)
        formLayout.addRow("字母和数字", validatorLineEdit)

        intLineEdit.setPlaceholderText("整数类型")
        doubleLineEdit.setPlaceholderText("双精度类型")
        validatorLineEdit.setPlaceholderText("字母和数字")

        intValidator = QIntValidator(self)
        intValidator.setRange(1, 99)

        doubleValidator = QDoubleValidator(self)
        doubleValidator.setRange(-3000, 3000)
        doubleValidator.setNotation(QDoubleValidator.StandardNotation)
        doubleValidator.setDecimals(2)

        reg = QRegExp('[a-zA-Z0-9]+$')
        validator = QRegExpValidator(self)
        validator.setRegExp(reg)

        intLineEdit.setValidator(intValidator)
        doubleLineEdit.setValidator(doubleValidator)
        validatorLineEdit.setValidator(validator)

        self.setLayout(formLayout)

if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = QlineEditValidator()
    ex.show()

    sys.exit(app.exec_())